<template>
  <div class="custom_pro_list">
    <ul class="switch_column" v-if="flag">
      <li v-for="item in proList">
        <img :src="item.img1" alt="" />
        <p>{{ item.proname }}</p>
        <p>{{ item.originprice }}</p>
      </li>
    </ul>
    <ul class="switch_list" v-else>
      <li v-for="item in proList" @click="goDetail(item.proid)">
        <div class="list_l">
          <img :src="item.img1" alt="" />
        </div>
        <div class="list_r">
          <p><van-text-ellipsis :content="item.proname" /></p>
          <p>{{ item.originprice }}</p>
        </div>
      </li>
    </ul>
    <div class="switch" @click="flag=!flag" v-if="scrollTop<300">
      <!-- <van-icon name="back-top" /> -->
      <van-icon size='30px' name="list-switch" v-if="flag" />
      <van-icon size='30px' name="list-switching" v-else />
    </div>
  </div>
</template>

<script setup>
let { proList,scrollTop } = defineProps(["proList","scrollTop"]);
console.log(proList);
import { ref } from "vue";
// 定义变量实现切换
const flag = ref(false);

// 跳转到详情
import {useRouter} from 'vue-router'
const router = useRouter();
const goDetail=(id)=>{
  // 为什么不行？
  //  router.push("/detail")
    router.push({name:'detail',params:{proid:id}})
}
</script>

<style scoped lang='less'>
.custom_pro_list {
  padding: 10px;
  .switch_column {
    column-count: 2;
    column-gap: 10px;
    li {
      width: 100%;
      min-height: 200px;
      margin-bottom: 10px;
      background-color: #fff;
      img {
        width: 100%;
        height: 100px;
      }
    }
  }
  .switch_list {
    li {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0px 5px;
      height: 80px;
      border-bottom: 1px solid #ccc;
      .list_l {
        width: 35%;
        img {
          width: 100%;
          height: 75px;
        }
      }
      .list_r {
        width: 60%;
      }
    }
  }
  .switch {
    width: 40px;
    height: 40px;
    border: 1px solid grey;
    background-color: #f6f6f6;
    position: fixed;
    bottom: 90px;
    right: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
  }
}
</style>